package com.ykht.proj.coupon.timer;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ykht.proj.coupon.Enum.ConfBrandPersonEnum;
import com.ykht.proj.coupon.entity.*;
import com.ykht.proj.coupon.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

@Component
@SuppressWarnings("all")
@Slf4j
@EnableScheduling
public class FxBrandTimer {

	@Resource
	private FxConfBrandPersonService fxConfBrandPersonService;
	/**
	 * 领取的优惠券过期
	 * 十分钟
	 */
	@Scheduled(cron = "0 0 0 * * ?")
	public void couponLogExpireTimer() {
		log.info("->定时任务：品牌配置 自动过期");
		AtomicInteger i = new AtomicInteger();
		List<FxConfBrandPerson> list = fxConfBrandPersonService.list(Wrappers.lambdaQuery(FxConfBrandPerson.class)
				.select(FxConfBrandPerson::getId)
				.eq(FxConfBrandPerson::getSwitchs, ConfBrandPersonEnum.RUNNING.getValue())
				.lt(FxConfBrandPerson::getEndTime, LocalDateTime.now()));
		list.stream().forEach(o->fxConfBrandPersonService.finish(o.getId()));
		log.info("->过期数量：{}",list.size());
	}


}
